Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Conversation

@tbarlow12
Copy link
Contributor

Resolves [AB#18737]

Copy link
Contributor

@wbreza wbreza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some feedback. Let me know if you have any questions.

AzureLoginService.servicePrincipalLogin = servicePrincipalLogin;

const sls = MockFactory.createTestServerless();
delete sls.variables['azureCredentials']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move these into a beforeEach or similar to keep it DRY?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only issue with that is the deletion of the credentials is specific to these tests only. Other tests depend on the credentials still being there

}
}

protected log(message: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)


private static createTestService(): Service {
public static createTestFunctionApp() {
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add return typings here.

webAppDelete = jest.fn();
sendFile = jest.fn();

WebSiteManagementClient.prototype.webApps = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods can be mocked by mocking the sub object directly. ex) WebApp.prototype.get = jest.fn(...)

beforeAll(() => {

// TODO: How to spy on defaul exported function?
const axiosMock = new MockAdapter(axios);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you find this mock adapter useful? I have mixed feelings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no... If I could make assertions on it, it would be amazing. I had to do something fairly hacky to validate the syncTriggers. I wasn't able to spy on axios directly. Maybe we can chat more about how to do that

} as any as Service;
}

public static createTestFunctions(functionCount = 3) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add typings to these mock factory functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of the reason for not having typings is my own not knowing what types they are 😆

But agreed. I'll do some more digging here

@tbarlow12 tbarlow12 force-pushed the tabarlow/function-app-service-tests branch from 74304a8 to ede2161 Compare June 4, 2019 16:38
Copy link
Contributor

@wbreza wbreza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saw a couple things that need attention before merging.

@@ -0,0 +1,4 @@
export * from "./azureProvider";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the exports?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make model imports easy. I can remove these

@@ -0,0 +1,8 @@
export interface ServerlessYml {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove Yml and maybe rename to ServerlessAzureConfig or similar.

it("sets up provider configuration", async () => {
const slsFunctionConfig = MockFactory.createTestSlsFunctionConfig();
const sls = MockFactory.createTestServerless();
Object.assign(sls.service, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do the functions config set if you are removing this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like with the updates to mock factory you need to now pass into createTestServerless ??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this instance in particular, since it's just using the createTestSlsFunctionConfig out of the box, that will already be in the sls object. If there is a different function config to pass, that can be achieved by doing:

createTestServerless({
   service: createTestService(functionConfig)
})

}

public async getMasterKey(functionApp) {
public async getMasterKey(functionApp?) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add typeref for functionApp


beforeEach(() => {
const slsConfig: any = {
...MockFactory.createTestService(MockFactory.createTestSlsFunctionConfig()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wbreza this is another option for using a custom config

Copy link
Contributor

@PIC123 PIC123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Much cleaner now too!

@tbarlow12 tbarlow12 merged commit bf2a978 into dev Jun 12, 2019
@tbarlow12 tbarlow12 deleted the tabarlow/function-app-service-tests branch June 12, 2019 20:29
tbarlow12 added a commit that referenced this pull request Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants